package com.yunhai.device.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.dto.Ret;
import com.yunhai.device.service.FdsMaterialUsageRulesetService;
import com.yunhai.model.entity.fds.FdsMaterialUsageRulesetEntity;
import com.yunhai.model.vo.fds.FdsMaterialUsageRulesetQuery;
import com.yunhai.model.vo.fds.FdsMaterialUsageRulesetVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/fdsMaterialUsageRuleset")
public class FdsMaterialUsageRulesetController {

	@Resource
	private FdsMaterialUsageRulesetService fdsMaterialUsageRulesetService;


	/**
	 * 获取 FdsMaterialUsageRuleset 分页列表
	 */
	@GetMapping("/pagination")
	public Ret getFdsMaterialUsageRulesetPagination(PaginationVo paginationVo, FdsMaterialUsageRulesetQuery fdsMaterialUsageRulesetQuery ) throws Exception {
		IPage page = fdsMaterialUsageRulesetService.getFdsMaterialUsageRulesetPagination(paginationVo, fdsMaterialUsageRulesetQuery );
		return Ret.toPage(page);
	}


	/**
	 * 获取 FdsMaterialUsageRuleset 所有数据
	 */
	@GetMapping("/allList")
	public Ret getFdsMaterialUsageRulesetAllList( FdsMaterialUsageRulesetQuery fdsMaterialUsageRulesetQuery ) throws Exception {
		List<FdsMaterialUsageRulesetEntity> list = fdsMaterialUsageRulesetService.getFdsMaterialUsageRulesetAllList( fdsMaterialUsageRulesetQuery );
		return Ret.ok(list);
	}


	/**
	 * 获取 FdsMaterialUsageRuleset 详情
	 */
	@GetMapping("/{id}")
	public Ret getFdsMaterialUsageRulesetDetailById(@PathVariable Long id) throws Exception {

	    FdsMaterialUsageRulesetEntity fdsMaterialUsageRulesetEntity = fdsMaterialUsageRulesetService.getFdsMaterialUsageRulesetDetail(id);
		return Ret.ok(fdsMaterialUsageRulesetEntity);
	}


	/**
	 * 新增 FdsMaterialUsageRuleset
	 * */
	@PostMapping("")
	public Ret addFdsMaterialUsageRuleset(@RequestBody FdsMaterialUsageRulesetVo fdsMaterialUsageRulesetVo) throws Exception {

		fdsMaterialUsageRulesetService.addFdsMaterialUsageRuleset(fdsMaterialUsageRulesetVo);
		return Ret.ok();
	}


	/**
	 * 更新 FdsMaterialUsageRuleset
	 * */
	@PutMapping("")
	public Ret updateFdsMaterialUsageRuleset(@RequestBody FdsMaterialUsageRulesetVo fdsMaterialUsageRulesetVo) throws Exception {

		fdsMaterialUsageRulesetService.updateFdsMaterialUsageRuleset(fdsMaterialUsageRulesetVo);
		return Ret.ok();
	}


	/**
	 * 删除 FdsMaterialUsageRuleset
	 * */
	@PostMapping("/batchRemove")
	public Ret batchRemoveFdsMaterialUsageRuleset( @RequestBody List<Long> ids ) throws Exception {

	    fdsMaterialUsageRulesetService.batchRemoveFdsMaterialUsageRuleset(ids);
		return Ret.ok();
	}
}
